home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #49 (Oct 89) / SC #49.sit / Driver Code / GNEFilter.a < prev    next >
Text File  |  1988-01-12  |  4KB  |  117 lines

  1.                 TITLE            'GNE filter'
  2.                 BLANKS            ON
  3.                 CASE            ON
  4.                 String            Pascal
  5.  
  6. *    The GNE Filter permits the pump driver to function asynchronously, but
  7. *  at non-interrupt level. Whenever a serial IO call completes, the serial
  8. *  completion routine posts an app1Evt with the parameter block pointer as
  9. *  the message. The GNE filter is called at the end of the _GetNextEvent trap,
  10. *  and thus receives all events. The filter first excludes all events other
  11. *  than app1Evts (passing then to the application for handling), then checks
  12. *  the ioRefnum field of the parameter block. If it is negative, the event
  13. *  belongs to a driver, and thus it is handled by the filter. The
  14. *  _GetNextEvent function code is returned as false, so that the application
  15. *  does not handle the event. If the ioRefnum is positive, the event is passed
  16. *  to the application.
  17. *    When the filter has found a driver app1Evt, the message will contain a
  18. *  pointer to a parameter block used for a serial IO driver. This parameter
  19. *  block contains a pointer to the currently executing pump driver parameter
  20. *  block in its ioMisc field, and this parameter block contains the pump
  21. *  driver reference number in its ioRefnum. We check this against a list of
  22. *  up to eight (arbitrary limit) reference numbers of cooperating drivers. If
  23. *  the driver is in the list, we pass it the event via an immediate control
  24. *  call. The routine does not check to see if the driver can handle app1Evts,
  25. *  simply because any driver which is not written to cooperate with this
  26. *  routine would be excluded by the check for membership in the cooperating 
  27. *  driver list.
  28. *    The routine is structured much like a driver, in that the first word is
  29. *  an offset to the routine, and local storage for data is incorporated into
  30. *  the routine. This is because the routine is installed by a driver, and thus
  31. *  cannot utilize application globals. Also, the rotuine is written so that it
  32. *  can be shared by several drivers to service their app1Evts. The routine
  33. *  is linked as a resource of type 'GNEF', and named 'GNEFilter',
  34. *  so that it can be loaded into the heap by the resource manager. 
  35.  
  36.  
  37.                 PRINT            OFF
  38.                 INCLUDE         'Traps.a'
  39.                 INCLUDE         'ToolEqu.a'
  40.                 INCLUDE         'QuickEqu.a'
  41.                 INCLUDE         'SysEqu.a'
  42.                 INCLUDE         'SysErr.a'
  43.                 INCLUDE         'GNEglobals.inc'
  44.                 INCLUDE         'Quickdraw.inc'
  45.                 LOAD            'FlowCtlMacs.d'
  46.                 PRINT            ON
  47.                 
  48. *  The stackframe for the routine.
  49.  
  50. StackFrame        RECORD            {A6Link},DECR
  51. Result            DS.W            1
  52. RetAddr            DS.L            1
  53. A6Link            DS.L            1
  54. LocalSize        equ                *
  55.                 ENDR
  56.                 
  57.                 MAIN
  58.  
  59.                 WITH EventRecord,StackFrame,GNEGlobals
  60.  
  61. Entry            DC.W            GNEFilter        ;Offset to GNE filter
  62.                 DCB.B            GNEGlobalSize,0
  63.  
  64.                 
  65. GNEFilter:
  66.  
  67. *  If the event is not an app1Evt, go to the next event in the GNE filter
  68. *  chain, which we previously stored in GNE_Next
  69.  
  70.                 LEA                Entry,A0
  71.                 CMP.W            #app1Evt,what(A1)
  72.                 BNE.S            Out
  73.  
  74. *  We have an app1Evt. Check to see if the ioRefnum is negative.
  75.  
  76.                 LINK            A6,#LocalSize
  77.                 MOVEM.L            A2/D1-D2,-(SP)
  78.                 MOVE.L            message(A1),A2
  79.                 MOVE.L            ioMisc(A2),A2
  80.                 MOVE.W            ioRefNum(A2),D1
  81.                 If#    GE    Then.S
  82.                     GoTo#.S    PreOut
  83.                 EndIf#
  84.  
  85. *  We have a negative ioRefnum. Check to see if it is in the list of ioRefnums
  86. *  we are cooperating with. If it is, pass the event to the driver by setting
  87. *  up a parameter block for an immediate call to the control routine.
  88.  
  89.                 MOVE.L            Control_Ptr(A0),A2
  90.                 LEA                Drvr_num(A0),A0
  91.                 MOVE.W            (A0)+,D2    
  92. Loop            For#    D2 DownTo #1    Do.S
  93.                     MOVE.W            (A0)+,D0
  94.                     If#    D0    EQ.W    D1    Then.S
  95.                         MOVE.W            D1,ioRefNum(A2)
  96.                         MOVE.W            #accEvent,csCode(A2)
  97.                         MOVE.L            A1,csParam(A2)
  98.                         MOVE.L            A2,A0
  99.                         _Control ,immed
  100.                         CLR.W            D0
  101.                         MOVE.W            D0,Result(A6)
  102.                         Leave#.S        Loop
  103.                     EndIf#
  104.                 EndF#
  105.                 
  106. PreOut:
  107.                 MOVEM.L            (SP)+,A2/D1-D2
  108.                 UNLK            A6
  109.                 LEA                Entry,A0
  110.  
  111. Out:                
  112.                 MOVE.L            GNE_Next(A0),A0
  113.                 JMP                (A0)
  114.                 
  115.                 ENDP
  116.                 
  117.                 END